package com.ciitc.zhgl.service.imp;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ciitc.zhgl.bean.Employee;
import com.ciitc.zhgl.bean.EmployeeExample;
import com.ciitc.zhgl.bean.EmployeeExample.Criteria;
import com.ciitc.zhgl.dao.EmployeeMapper;
import com.ciitc.zhgl.service.EmployeeService;
@Service
public class EmployeeServiceImpl implements EmployeeService {
	
	@Autowired
	EmployeeMapper em;

	@Override
	public List<Employee> getAll() {
		return em.selectByExampleWithDept(null);
	}

	@Override
	public void saveEmp(Employee employee) {
		em.insertSelective(employee);
	}

	@Override
	public boolean checkUser(String empName) {
		EmployeeExample example = new EmployeeExample();
		Criteria criteria = example.createCriteria();
		criteria.andEmpNameEqualTo(empName);
		
		long count = em.countByExample(example);
		return count == 0;
	}

	@Override
	public Employee getEmp(Integer id) {
		Employee employee = em.selectByPrimaryKey(id);
		return employee;
	}

	@Override
	public void updateEmp(Employee employee) {
		em.updateByPrimaryKeySelective(employee);
	}

	@Override
	public void deleteEmp(Integer empId) {
		em.deleteByPrimaryKey(empId);
	}

	@Override
	public void saveEmployee(Employee emp) {
		em.insertSelective(emp);
		
	}

}
